/** * 浜挎柊绉戞妧锛堟俯宸炴槗灏氫俊鎭妧鏈湁闄愬叕鍙革級--- 寮犳磱 * 2020-06-06 */ document.body.addEventListener('touchstart', function() { }); $('body').children().click(function() { }); const ua = navigator.userAgent.toLowerCase(); const isWeixin = ua.indexOf('micromessenger') != - 1; let viewWidth = $(window).width(); let viewHeight = $(window).height(); const pathname = window.location.pathname; let scrollSwitch = false; let prevTop = 0, currTop = 0; let tPoint = 15; $(window).scroll(function() { currTop = $(window).scrollTop(); if (currTop > tPoint) { if (!scrollSwitch) { $('#head').addClass('small'); $('#to-top').addClass('active'); scrollSwitch = true; } } else { if (scrollSwitch) { $('#head').removeClass('small'); $('#to-top').removeClass('active'); scrollSwitch = false; } } if (viewWidth >= 1200) { if (currTop > viewHeight) { $('#banner').hide(); $('.to-top-container').addClass('active'); } else { $('#banner').show(); $('.to-top-container').removeClass('active'); } } else { if (currTop > viewWidth) { $('#banner').hide(); $('.to-top-container').addClass('active'); } else { $('#banner').show(); $('.to-top-container').removeClass('active'); } } }); /** * 绉诲姩绔痭av */ $('#nav-btn').on('click', function() { if (!$('.nav-container').hasClass('active')) { $('#nav-btn').addClass('active'); $('.nav-container').addClass('active'); $('html,body').css('overflow', 'hidden'); } else { $('#nav-btn').removeClass('active'); $('.nav-container').removeClass('active'); $('html,body').css('overflow', 'unset'); } }); /** * 涓婁笅婊氬姩banner瑙嗗樊 */ if (viewWidth>=1080) { $(document).scroll(function() { let scrollTop = $(document).scrollTop(); let sk = scrollTop * 0.2; $('#banner').css('top', - sk + 'px'); if (scrollTop > 200) { let opacity = 200 / scrollTop; opacity = opacity > 1 ? 1 : opacity; $('#banner .swiper-container').css('opacity', opacity); } else { $('#banner .swiper-container').css('opacity', 1); } }); } /** * 杩斿洖椤堕儴鎸夐挳 */ $('.to-top').on('click', function() { $('html, body').stop().animate({scrollTop:0}); }); (function($) { $.fn.loadmore = function(options) { var defaults = { recordcount: 0, page: 1, pagecount: 1, pagesize: 0, url: '', loading: '.loading-box', box: '.list', a: '.more', last: '.last-num', lastnum: 'span', oncomplete: function(data) { }//瀹屾垚鍚庝簨浠 } var opts = $.extend(defaults, options); var ele = $(this); if (opts.page >= opts.pagecount || opts.recordcount == 0) { ele.hide(); $(opts.box).css('margin-bottom', '80px'); console.log('鎵€鏈変俊鎭凡鍔犺浇瀹屾瘯銆?); return false; } ele.find(opts.a).on('click', function() { opts.page ++; ele.hide(); $(opts.loading).show(); if (opts.page > opts.pagecount || opts.recordcount == 0) { ele.hide(); console.log('鎵€鏈変俊鎭凡鍔犺浇瀹屾瘯銆?); return false; } var settings = { type: 'POST', url: opts.url + '/page/' + opts.page, dataType: 'html', error: function(XHR, textStatus, errorThrown) { console.log("XHR=" + XHR + "\ntextStatus=" + textStatus + "\nerrorThrown=" + errorThrown); }, success: function(data, textStatus) { setTimeout(function() { $(opts.box).append(data); ele.find(opts.a).attr('href', opts.url + '/page/' + (opts.page + 1)); ele.show(); var lastnum = opts.recordcount - opts.page * opts.pagesize; if (lastnum <= 0) { $(opts.last).html('銆€
銆€'); } else { $(opts.last).find(opts.lastnum).html(lastnum); } $(opts.loading).hide(); if (opts.page >= opts.pagecount) ele.hide(); opts.oncomplete(data); }, 360); }, headers: {'Pull-Ajax': 'true'} }; $.ajax(settings); return false; }); } })(jQuery); (function($) { $.fn.wxImgShow = function() { var ele = $(this); var imgs = new Array(); for (var i = 0; i < ele.length; i ++) { imgs.push(ele.eq(i).attr('src')); } //console.log(imgs); ele.on('click', function() { WeixinJSBridge.invoke('imagePreview', { 'current': $(this).attr('src'), 'urls': imgs }); }); } })(jQuery); /** * 鏍规嵁閿氱偣瀹氫綅鍒扮浉搴旈珮搴︿綅缃 */ (function($) { $.fn.reach = function() { var ele = $(this); ele.on('click', function() { const url = $(this).attr('href'); // 濡傛灉涓嶆槸褰撳墠椤甸潰鍒欑洿鎺ヨ繑鍥 if (window.location.pathname != url.substring(0, $(this).attr('href').indexOf('#'))) { return; } // 寰楀埌瑕佸畾浣嶇殑鍏冪礌 const p = url.substring(url.indexOf('#')); if ($(p).length) { // 寰楀埌鍏冪礌鐨勪綅缃 const scrollTop = $(p).offset().top; // 璺冲埌浣嶇疆 $('html,body').animate({scrollTop: scrollTop+'px'}, 600, 'easeOutExpo'); // 鏀瑰彉url鐨勫€ window.history.pushState(null,null, url); } return false; }); } })(jQuery); const reach = function() { const hash = window.location.hash; if (hash) { // 寰楀埌瑕佸畾浣嶇殑鍏冪礌 if ($(hash).length) { // 寰楀埌鍏冪礌鐨勪綅缃 const scrollTop = $(hash).offset().top; // 璺冲埌浣嶇疆 $('html,body').animate({scrollTop: scrollTop + 'px'}, 600, 'easeOutExpo'); } } } $('#foot dd>a').reach();